package leetcode.code1674;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int minMoves(int[] nums, int limit) {
		int[] arr = new int[(limit << 1) + 2];
		int n = nums.length;
		for (int i = 0; i < (n >> 1); i++) {
			int num1 = nums[i], num2 = nums[n - 1 - i];
			int min = Math.min(num1, num2);
			int max = Math.max(num1, num2);
			int sum = num1 + num2;
			arr[1] += 2;
			arr[min + 1] -= 1;
			arr[max + limit + 1] += 1;
			arr[sum] -= 1;
			arr[sum + 1] += 1;
		}
		int ans = Integer.MAX_VALUE, sum = 0;
		for (int i = 1; i < arr.length - 1; i++) {
			sum += arr[i];
			ans = Math.min(ans, sum);
		}
		return ans;
	}

	@Override
	public void debug4() {
		H.compare(1, this.minMoves(H.str2array3("[1,2,4,3]"), 4));
		H.compare(2, this.minMoves(H.str2array3("[1,2,2,1]"), 2));
		H.compare(0, this.minMoves(H.str2array3("[1,2,1,2]"), 2));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
